package com.ttt.gdfood.controller;

import com.ttt.gdfood.entity.Comment;
import com.ttt.gdfood.entity.Video;
import com.ttt.gdfood.service.VideoService;
import com.ttt.gdfood.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/video")
@CrossOrigin
public class VideoController {
    @Autowired
    VideoService videoService;

    @GetMapping("/getAll")
    List<Video> getAll(){
        return videoService.getAllVideo();
    }

    @PostMapping("/addVideo")
    public JsonResult<Void> addVideo(@RequestBody Video video) {
        // 创建返回值
        JsonResult<Void> result = new JsonResult<Void>();
        try {
// 调用业务对象执行添加
            videoService.addVideo(video);
            // 响应成功
            result.setState(200);
            result.setMessage("发表成功");
        } catch (Exception e) {
// 添加异常
            result.setState(500);
            result.setMessage("发表失败");
        }
        return result;
    }
}
